package com.us.simple.sys.controller;

import com.us.simple.common.advice.Rest;
import com.us.simple.common.advice.RestBody;
import com.us.simple.sys.service.IUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api( tags = "登录")
@RestController
@RequestMapping
@Slf4j
public class LoginController {
    @Autowired
    private IUserInfoService userInfoService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public Rest login(@RequestBody LoginDto loginDto) {
        Map<String, Object> login = userInfoService.login(loginDto.username, loginDto.password);
        return RestBody.okData(login);
    }

    @GetMapping("/logout")
    @ApiOperation("登出")
    public Rest logout(HttpServletRequest request) {
        userInfoService.logout(request);
        return RestBody.okData("操作成功");
    }

    @Data
    public static class LoginDto{
        String username;
        String password;
    }
}
